from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem



class GTable(QTableWidget):

    def setData(self, title, data):
        self.setRowCount(len(data))  # 设置行数--不包括标题列
        self.setColumnCount(len(title))  # 设置列数
        titles = [i.label for i in title]
        pro = [i.pro for i in title]

        self.setHorizontalHeaderLabels(titles)
        i, j = 0, 0
        for d in data:
            for p in pro:
                newItem = QTableWidgetItem(str(d[p]))
                self.setItem(i, j, newItem)
                j += 1
        i += 1
